import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 替换字符
 * User: DELL
 * Date: 2024-05-24
 * Time: 9:03
 */
public class Main9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder builder = new StringBuilder(scanner.next());
        int m = scanner.nextInt();
        while (m-- > 0) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            char ch1 = scanner.next().charAt(0);
            char ch2 = scanner.next().charAt(0);
            for (int i = l; i <= r; i++) {
                if (builder.charAt(i - 1) == ch1) {
                    builder.setCharAt(i - 1, ch2);
                }
            }
        }
        System.out.println(builder.toString());
    }
}
